import { openIdGet as openIdGetApi } from "../api/api"
import { openIdSet, openIdGet } from "../storage/openId";
import { sessionKeySet } from "../storage/sessionKey"

export default {
  init() {

    const openIdStorage = openIdGet();

    if (openIdStorage) {
      return;
    }

    wx.login({
      success: res => {
        openIdGetApi({ code: res.code }).then(res => {
          if (!res) return;
          const { openid, session_key } = res;
          openIdSet(openid);
          sessionKeySet(session_key);
        })
      }
    });
  }
}

